<template>
  <div>
    <el-card>
      <div slot="header">
        <el-row :gutter="24">
          <el-col :span="12">
            <strong>实验答疑</strong>
          </el-col>
          <el-col :span="12" class="frx">
            <el-button type="primary" @click="showAdd = true"
              >添加答疑</el-button
            >
          </el-col>
        </el-row>
      </div>
      <el-row>
        <el-table :data="source">
          <el-table-column label="姓名" prop="username"></el-table-column>
          <el-table-column label="学校/单位" prop="school"></el-table-column>
          <el-table-column
            label="实验答疑"
            prop="question"
            width="300px"
          ></el-table-column>
          <el-table-column label="创建时间">
            <template slot-scope="scope">{{
              $parseDate(scope.row.createTime)
            }}</template>
          </el-table-column>
          <el-table-column label="是否答复" width="100px">
            <template slot-scope="scope">
              <span v-if="scope.row.isAnswer === 1">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="openDetail(scope.row)"
                >查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-pagination
        :page-size="size"
        :total="total"
        :current-page.sync="page"
        @current-change="loadSource"
      ></el-pagination>
    </el-card>
    <AnwserDetailDialog
      :visible.sync="showDetail"
      :id="id"
      :username="unmae"
    ></AnwserDetailDialog>
    <AddAnwserDialog :visible.sync="showAdd"></AddAnwserDialog>
  </div>
</template>

<script>
import AnwserDetailDialog from '../../../components/dialog/AnwserDetailDialog.vue'
import AddAnwserDialog from '../../../components/dialog/AddAnwserDialog.vue'
import Qapi from '../../../api/Question.js'
export default {
  data() {
    return {
      page: 1,
      size: 15,
      total: 15,
      showDetail: false,
      showAdd: false,
      id: 0,
      unmae: '',
      source: []
    }
  },
  components: {
    AnwserDetailDialog,
    AddAnwserDialog
  },
  methods: {
    openDetail(row) {
      this.showDetail = true
      this.id = row.id
      this.unmae = row.username
    },
    addAnwser() {},
    loadSource() {
      this.axios
        .get(Qapi.findAll, {
          params: { pageNum: this.page, pageSize: this.size }
        })
        .then(res => {
          if (res.data.status === 0) {
            this.source = res.data.data.list
            this.total = res.data.data.total
          }
        })
    }
  },
  mounted() {
    this.loadSource()
  }
}
</script>

<style></style>
